import axios, { AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'
// import message from '@/hooks/message.ts'
// import NProgress from 'nprogress'

// NProgress.configure({ showSpinner: false })

// 创建axios实例
const api = (config: AxiosRequestConfig) => {
  const instance = axios.create({
    baseURL: import.meta.env.VITE_BASEURL,
    url: config.url,
    method: config.method || 'GET',
    //过期时间
    timeout: 1000 * 30,
    headers: {}
  })
  // 请求拦截器
  instance.interceptors.request.use((request: InternalAxiosRequestConfig) => {
    // NProgress.start()
    return request
  })

  // 响应拦截器
  instance.interceptors.response.use(
    (response) => {
      // NProgress.done()
      return response.data
    },
    (error) => {
      // NProgress.done()
      return Promise.reject(error)
    }
  )

  return instance(config)
}

export default api
